﻿using Fierce.Utility.Helper;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;

namespace Fierce.MvcExtend
{
    public static class SessionFactory
    {
        public static T Get<T>(this ISession session, string key)
        {
            var value = session.GetString(key);

            if (value != null)
            {
                return JsonHelper.Deserialize<T>(value);
            }

            return default(T);
        }

        public static void Set<T>(this ISession session, string key, T value)
        {
            session.SetString(key, JsonHelper.Serialize(value));
        }
    }
}